flag_no_deps: bool,
flag_open: bool,
flag_verbose: bool,
+ flag_package: Option<String>,
}
pub const USAGE: &'static str = "
cargo doc [options]
Options:
- -h, --help Print this message
- --open Opens the docs in a browser after the operation
- --no-deps Don't build documentation for dependencies
- -j N, --jobs N The number of jobs to run in parallel
- --features FEATURES Space-separated list of features to also build
- --no-default-features Do not build the `default` feature
- --manifest-path PATH Path to the manifest to document
- -v, --verbose Use verbose output
+ -h, --help Print this message
+ --open Opens the docs in a browser after the operation
+ -p SPEC, --package SPEC Package to document
+ --no-deps Don't build documentation for dependencies
+ -j N, --jobs N The number of jobs to run in parallel
+ --features FEATURES Space-separated list of features to also build
+ --no-default-features Do not build the `default` feature
+ --manifest-path PATH Path to the manifest to document
+ -v, --verbose Use verbose output
By default the documentation for the local package and all dependencies is
built. The output is all placed in `target/doc` in rustdoc's usual format.
+
+If the --package argument is given, then SPEC is a package id specification
+which indicates which package should be documented. If it is not given, then the
+current package is documented. For more information on SPEC and its format, see
+the `cargo help pkgid` command.
";
pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
dev_deps: false,
features: options.flag_features.as_slice(),
no_default_features: options.flag_no_default_features,
- spec: None,
+ spec: options.flag_package.as_ref().map(|s| s.as_slice()),
lib_only: false
},
};
+use std::io::fs::PathExtensions;
use std::collections::HashSet;
+use core::PackageIdSpec;
use core::source::Source;
use ops;
use sources::PathSource;
let mut lib_names = HashSet::new();
let mut bin_names = HashSet::new();
- for target in package.get_targets().iter().filter(|t| t.get_profile().is_doc()) {
- if target.is_lib() {
- assert!(lib_names.insert(target.get_name()));
- } else {
- assert!(bin_names.insert(target.get_name()));
+ if options.compile_opts.spec.is_none() {
+ for target in package.get_targets().iter().filter(|t| t.get_profile().is_doc()) {
+ if target.is_lib() {
+ assert!(lib_names.insert(target.get_name()));
+ } else {
+ assert!(bin_names.insert(target.get_name()));
+ }
}
- }
- for bin in bin_names.iter() {
- if lib_names.contains(bin) {
- return Err(human("Cannot document a package where a library and a \
- binary have the same name. Consider renaming one \
- or marking the target as `doc = false`"))
+ for bin in bin_names.iter() {
+ if lib_names.contains(bin) {
+ return Err(human("Cannot document a package where a library \
+ and a binary have the same name. Consider \
+ renaming one or marking the target as \
+ `doc = false`"))
+ }
}
}
try!(ops::compile(manifest_path, &mut options.compile_opts));
if options.open_result {
- use std::io::fs::PathExtensions;
+ let name = match options.compile_opts.spec {
+ Some(spec) => try!(PackageIdSpec::parse(spec)).get_name().to_string(),
+ None => {
+ match lib_names.iter().nth(0) {
+ Some(s) => s.to_string(),
+ None => return Ok(())
+ }
+ }
+ };
- match lib_names.iter().nth(0).map(|l| package.get_absolute_target_dir()
- .join("doc").join(*l).join("index.html"))
- {
- Some(ref path) if path.exists() => open_docs(path),
- _ => ()
+ let path = package.get_absolute_target_dir().join("doc").join(name)
+ .join("index.html");
+ if path.exists() {
+ open_docs(&path);
}
}
Consider renaming one or marking the target as `doc = false`
"));
})
+
+test!(doc_dash_p {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+
+ [dependencies.a]
+ path = "a"
+ "#)
+ .file("src/lib.rs", "extern crate a;")
+ .file("a/Cargo.toml", r#"
+ [package]
+ name = "a"
+ version = "0.0.1"
+ authors = []
+
+ [dependencies.b]
+ path = "../b"
+ "#)
+ .file("a/src/lib.rs", "extern crate b;")
+ .file("b/Cargo.toml", r#"
+ [package]
+ name = "b"
+ version = "0.0.1"
+ authors = []
+ "#)
+ .file("b/src/lib.rs", "");
+
+ assert_that(p.cargo_process("doc").arg("-p").arg("a"),
+ execs().with_status(0)
+ .with_stdout(format!("\
+{compiling} b v0.0.1 (file://[..])
+{compiling} a v0.0.1 (file://[..])
+", compiling = COMPILING).as_slice()));
+})